package com.snake.spring.boot.smaple.retrofit.utils;

import cn.hutool.core.util.IdcardUtil;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Slf4j
public class IdcardUtilTest {
    public static void main(String[] args) {


        /**
         * isValidCard 验证身份证是否合法
         */
        String idCard = "412727199005010732";
        boolean validCard = IdcardUtil.isValidCard(idCard);
        log.info("验证身份证是否合法:{}", validCard);
        /**
         * 获取生日
         */
        String birthByIdCard = IdcardUtil.getBirthByIdCard(idCard);
        log.info("获取生日:{}", birthByIdCard);
        /**
         * 获取年龄
         */
        int ageByIdCard = IdcardUtil.getAgeByIdCard(idCard);
        log.info("获取年龄:{}", ageByIdCard);

        LocalDateTime localDateTime = LocalDateTime.parse("2018-03-13 14:41:14", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        int ageByIdCard1 = IdcardUtil.getAgeByIdCard(idCard, date);
        log.info("获取年龄:{}", ageByIdCard1);
        /**
         * 获取生日年
         */
        Short yearByIdCard = IdcardUtil.getYearByIdCard(idCard);
        log.info("获取生日年:{}", yearByIdCard);
        /**
         * 获取生日月
         */
        Short monthByIdCard = IdcardUtil.getMonthByIdCard(idCard);
        log.info("获取生日月:{}", monthByIdCard);
        /**
         * 获取生日天
         */
        Short dayByIdCard = IdcardUtil.getDayByIdCard(idCard);
        log.info("获取生日天:{}", dayByIdCard);
        /**
         * 获取性别
         */
        int genderByIdCard = IdcardUtil.getGenderByIdCard(idCard);
        log.info("获取性别:{}", genderByIdCard);
        /**
         * 获取省份
         */
        String provinceByIdCard = IdcardUtil.getProvinceByIdCard(idCard);
        log.info("获取省份:{}", provinceByIdCard);
    }


}
